FIND_PACKAGE(X11)
INCLUDE_DIRECTORIES(${X11_X11_INCLUDE_PATH})
LINK_DIRECTORIES(${X11_LIBRARY_DIR})

FIND_PATH(
  PETSC_INCLUDE_DIR
  NAMES petsc.h
  PATHS /usr/include/petsc /usr/local/petsc-2.3.3-p8/include
  )
FIND_PATH(
  PETSCCONF_INCLUDE_DIR
  NAMES petscconf.h
  PATHS /usr/include/petsc /usr/local/petsc-2.3.3-p8/bmake/linux-gnu-c-debug/
  )

IF( PETSCCONF_INCLUDE_DIR EQUAL PETSC_INCLUDE_DIR )
  SET(CMAKE_REQUIRED_INCLUDES "${PETSC_INCLUDE_DIR};${CMAKE_REQUIRED_INCLUDES}")
ELSE( PETSCCONF_INCLUDE_DIR EQUAL PETSC_INCLUDE_DIR )
  SET(CMAKE_REQUIRED_INCLUDES "${PETSC_INCLUDE_DIR};${PETSCCONF_INCLUDE_DIR};${CMAKE_REQUIRED_INCLUDES}")
ENDIF( PETSCCONF_INCLUDE_DIR EQUAL PETSC_INCLUDE_DIR )

MESSAGE( STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")

CHECK_INCLUDE_FILE(petscconf.h HAVE_PETSCCONF_H)
CHECK_INCLUDE_FILE(petsc.h HAVE_PETSC_H)
IF ( HAVE_PETSC_H )
  ADD_DEFINITIONS( -DHAVE_PETSC_H -DHAVE_PETSC )
ENDIF( HAVE_PETSC_H )


#FIND_LIBRARY(PETSC_LIB_MPIUNI    mpiuni    PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug QUIET )
FIND_LIBRARY(PETSC_LIB_PETSC     petsc     PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)
FIND_LIBRARY(PETSC_LIB_PETSCDM   petscdm   PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)
FIND_LIBRARY(PETSC_LIB_PETSCVEC  petscvec  PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)
FIND_LIBRARY(PETSC_LIB_PETSCMAT  petscmat  PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)
FIND_LIBRARY(PETSC_LIB_PETSCKSP  petscksp  PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)
FIND_LIBRARY(PETSC_LIB_PETSCSNES petscsnes PATHS /usr/local/petsc-2.3.3-p8/lib/linux-gnu-c-debug)


SET(PETSC_LIBRARIES
  ${PETSC_LIB_PETSCSNES}
  ${PETSC_LIB_PETSCKSP}
  ${PETSC_LIB_PETSCMAT}
  ${PETSC_LIB_PETSCVEC}
  ${PETSC_LIB_PETSCDM}
  ${PETSC_LIB_PETSC}
#  ${PETSC_LIB_MPIUNI}
  ${X11_LIBRARIES}
)
